class Reader:
    def __init__(self, DBName, DBUser):
        self.DBName = DBName
        self.DBUser = DBUser
        self.connection = None

    def connect(self): 
        attemptCount = 0
        self.connection = None
        while True:
            try:
                self.connection = pymssql.connect(dbname=self.DBName, user=self.DBUser)
                break
            except:
                secs = 2
                attemptCount += 1
                if attemptCount > 3:
                    attemptCount = 0
                    secs *= 10
                MSLogger.logWarn('Connection failed to SEC FB(%s@%s). Sleep %d secs before new attempt' % (self.dbPath, self.dbUser, secs))
                sleep(secs)
                continue
        return True

    def forceConnection(self):
        #TBD check by getting cursor: except - reconn, not - ok
        if self.connection == None:
            self.connect()
            MSLogger.logDebug('Connected to SEC DB')
        return True


    def readEvents_Processing(self):
        try:
            cur = self.connection.cursor()
            query = "SELECT event_id FROM op_processing"
            cur.execute(query)
            ret = []
            for e in cur.fetchall():
                id = e[0]
                ret.append(id)
                #query = "SELECT event_id FROM eevents"
                #TBD op_processing is mapped to eevents via event_id (get fields of eevents)
                #TBD how is it mapped to activeevents
            return ret
        except Exception, err:
            MSLogger.logError('Reader: Processing failed: error(%s)' % (str(err)))
            continue
